<template>
  <div class="hello">
    <div
      v-show="dataList"
      v-for="(data, index) in dataList"
      :key="index"
      class="card"
    >
      <a :href="data.html_url"><img :src="data.avatar_url" /></a><br />
      <span class="card-text">{{ data.login }}</span>
    </div>

    <!-- 展示欢迎词 -->
    <h1 v-show="isFirst">欢迎使用！</h1>
    <!-- 展示加载中 -->
    <h1 v-show="isLoading">加载中....</h1>
    <!-- 展示错误信息 -->
    <h1 v-show="errMsg">{{ errMsg }}</h1>
  </div>
</template>

<script>
export default {
  name: "ReturnList",
  data() {
    return {
      dataList: [],
      isFirst: true,
      isLoading: false,
      errMsg: "",
    };
  },
  mounted() {
    this.$bus.$on("updataData", (data) => {
      this.dataList = data;
      this.isLoading = false;
    });
    this.$bus.$on("load", (flag, ...error) => {
      console.log('flag',flag);
      this.isFirst = false;
      this.isLoading = flag;
      this.errMsg = error.toString();
    });
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.card {
  float: left;
  width: 200px;
  height: 300px;
  border: 1px solid yellow;
  text-align: center;
  padding: 10px;
  margin: 5px;
  margin-bottom: 10px;
}
.card > a > img {
  width: 100%;
  height: 200px;
  margin-bottom: 50px;
}
.card a img {
  width: 100%;
  height: 200px;
}
.card-text {
  font: 125%;
}

.card:hover {
  border: 1px solid #777;
}
h1 {
  text-align: center;
  font: 125%;
  font-family: "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande",
    "Lucida Sans", Arial, sans-serif;
  color: #ad2121;
}
</style>

